
*************************************************************************
*Table A.4: Outcome missingness by treatment status: surveyed households
*This table reports the rate at which various household outcomes measured in endline one (January - March) are not observed, by treatment status. We include only surveyed households
*************************************************************************


use "${SurveyDataDir}/JH_ePOS_HH_DataforAnalysis.dta",clear

* Keep if surveyed or classified as ghost
keep if ss_code == "SS01"


svyset [pw = pweight]

count if ghost_final == 1
scalar ghosts = r(N)
scalar obs = 3960   

*Get relative weights of AAY and PH rationcard holders by whether RC is in an urban area
sum pweight if rationcardtype == "AAY" & isurban == 0
scalar AAY_weight0 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 0
scalar PH_weight0 = r(sum)

sum pweight if rationcardtype == "AAY" & isurban == 1
scalar AAY_weight1 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 1
scalar PH_weight1 = r(sum)


*Generate indicators for sampled rationcard status
gen b4a_aware_ration_card_3 = (b4a_aware_ration_card == 3) 
gen b4a_aware_ration_card_4_88 = inlist(b4a_aware_ration_card, 4, -88)

local allMIvar ""

* Missing answers
foreach var of varlist c6_WTA_jan17 c6_WTA_feb17 c6_WTA_mar17  c25_quality_rice c25_quality_wheat c25_quality_sugar c25_quality_salt c25_quality_kero c26_adulterate_scale_rice c26_adulterate_scale_wheat c26_adulterate_scale_sugar c26_adulterate_scale_salt c26_adulterate_scale_kero c_total_access_cost_mar17  c_access_cost_jan17 c_access_cost_feb17  c_access_cost_mar17  b_overcharge_*_jan17 b_overcharge_*_feb17 b_overcharge_*_mar17  d2_co_*_kirana_price_fps d2_co_*_kirana_price {
	gen MI_`var' = (mi(`var'))     //count how many missing for each var
	replace `var'=MI_`var'
	local allMIvar "`allMIvar' "`var'" "
	
}


***These are the outcomes for the overall sample
unab outcomesAll: b4a_aware_ration_card_3 b4a_aware_ration_card_4_88 c6_WTA_jan17 c6_WTA_feb17 c6_WTA_mar17 c25_quality_rice c25_quality_wheat c25_quality_sugar c25_quality_salt c25_quality_kero c26_adulterate_scale_rice c26_adulterate_scale_wheat c26_adulterate_scale_sugar c26_adulterate_scale_salt c26_adulterate_scale_kero c_access_cost_jan17  c_access_cost_feb17  c_access_cost_mar17   c_total_access_cost_mar17 b_overcharge_rice_jan17 b_overcharge_rice_feb17 b_overcharge_rice_mar17  b_overcharge_wheat_jan17 b_overcharge_wheat_feb17 b_overcharge_wheat_mar17 b_overcharge_sugar_jan17 b_overcharge_sugar_feb17 b_overcharge_sugar_mar17  b_overcharge_salt_jan17 b_overcharge_salt_feb17 b_overcharge_salt_mar17  b_overcharge_kero_jan17 b_overcharge_kero_feb17 b_overcharge_kero_mar17 b_overcharge_total_jan17 b_overcharge_total_feb17 b_overcharge_total_mar17 d2_co_1_kirana_price_fps d2_co_2_kirana_price_fps d2_co_3_kirana_price_fps d2_co_4_kirana_price_fps d2_co_5_kirana_price_fps d2_co_1_history_kirana_price d2_co_2_history_kirana_price d2_co_3_history_kirana_price d2_co_4_history_kirana_price d2_co_5_history_kirana_price


***Label vars for outputting display
lab var b4a_aware_ration_card_3 "Sampled rationcard is inactive"
lab var b4a_aware_ration_card_4_88 "Household does not know of sampled rationcard"
lab var c_total_access_cost_mar17 "Total access cost in March"
lab var c_access_cost_mar17 "Access cost in March"
lab var c_access_cost_jan17 "Access cost in January"
lab var c_access_cost_feb17  "Access cost in February"
lab var c26_adulterate_scale_wheat "Wheat was adulterated"
lab var c26_adulterate_scale_sugar "Sugar was adulterated"
lab var c26_adulterate_scale_salt "Salt was adulterated"
lab var c26_adulterate_scale_rice "Rice was adulterated"
lab var c26_adulterate_scale_kero "Kerosene was adulterated"
lab var c25_quality_wheat "Wheat was low quality"
lab var c25_quality_sugar "Sugar was low quality"
lab var c25_quality_salt "Salt was low quality"
lab var c25_quality_rice "Rice was low quality"
lab var c25_quality_kero "Kerosene was low quality"
lab var b_overcharge_wheat_mar17 "Overcharge on wheat in March"
lab var b_overcharge_wheat_jan17 "Overcharge on wheat in January"
lab var b_overcharge_wheat_feb17 "Overcharge on wheat in February"
lab var b_overcharge_total_mar17 "Total overcharge in March"
lab var b_overcharge_total_jan17 "Total overcharge in January"
lab var b_overcharge_total_feb17 "Total overcharge in February"
lab var b_overcharge_sugar_mar17 "Overcharge on sugar in March"
lab var b_overcharge_sugar_jan17 "Overcharge on sugar in January"
lab var b_overcharge_sugar_feb17 "Overcharge on sugar in February"
lab var b_overcharge_salt_mar17 "Overcharge on salt in March"
lab var b_overcharge_salt_jan17 "Overcharge on salt in January"
lab var b_overcharge_salt_feb17 "Overcharge on salt in February"
lab var b_overcharge_rice_mar17 "Overcharge on rice in March"
lab var b_overcharge_rice_jan17 "Overcharge on rice in January"
lab var b_overcharge_rice_feb17 "Overcharge on rice in February"
lab var b_overcharge_kero_mar17 "Overcharge on kerosene in March"
lab var b_overcharge_kero_jan17 "Overcharge on kerosene in January"
lab var b_overcharge_kero_feb17 "Overcharge on kerosene in February"
label var	c6_WTA_jan17	"Willingness to accept in January"
label var	c6_WTA_feb17	"Willingness to accept in February"
label var	c6_WTA_mar17	"Willingness to accept in March"
label var	d2_co_1_kirana_price_fps	"FPS-level market price of rice in March"
label var	d2_co_2_kirana_price_fps	"FPS-level market price of wheat in March"
label var	d2_co_3_kirana_price_fps	"FPS-level market price of sugar in March"
label var	d2_co_4_kirana_price_fps	"FPS-level market price of salt in March"
label var	d2_co_5_kirana_price_fps	"FPS-level market price of kerosene in March"
label var	d2_co_1_history_kirana_price	"HH-level market price of rice in March"
label var	d2_co_2_history_kirana_price	"HH-level market price of wheat in March"
label var	d2_co_3_history_kirana_price	"HH-level market price of sugar in March"
label var	d2_co_4_history_kirana_price	"HH-level market price of salt in March"
label var	d2_co_5_history_kirana_price	"HH-level market price of kerosene in March"

	 



* outputting the tables (using Attrition_table function)
loc stratification "strata"
loc clusteredSE "Yes"
eststo all: Attrition_table_svy "`outcomesAll'" "`stratification'" "`clusteredSE'"



#delimit ;

esttab all using "${OutputDir}/TableA_4.tex", stats( ) 
cells("Mean1(fmt(%12.2g) label(Treatment)) Mean0(fmt(%12.2g) label(Control)) b(star fmt(%12.2g) label(Difference)) p(fmt(2) label(\(p\)-value))") 
 star(* .10 ** .05 *** .01) booktabs nonumber alignment(r r r r) noobs mlabel("") label replace longtable
 substitute(
 "                    &            &            &            &            \\" ""
	"\begin{longtable}{l*{1}{r r r r}}" "\begin{longtable}[h]{l*{1}{r r r r}}    \caption{Outcome missingness by treatment status: surveyed households}   \label{tab:missingness} \\");

#delimit cr
